<?php
class Gongwenread_ctl extends Ctl{
    function __construct(){
    }
    function main(array $xxfget) {
        $this::sessver();
        $type=!empty($_POST['type'])?$_POST['type']:false;
		$type=!empty($xxfget['type'])?$xxfget['type']:$type;
        if(!$type){
            $uid=XXF_UID;
            $result=xdb::getInstance()->getarray("select *,n.atime as natime,n.uid as nuid,n.id as nid from `user` as u,news as n,user_gongwen_news as ugn where u.id=ugn.uid and ugn.nid=n.id and ugn.uid=$uid order by ugn.id desc");
        	$this::show('gongwenread',compact('result'));
        }else{
            $this::$type($xxfget);
        }
    }
    function showgongwen($xxfget){
        $nid=$xxfget['nid'];
        $uid=XXF_UID;
        $ugnid=xdb::getInstance()->getvar("select id from user_gongwen_news where nid=$nid and uid=$uid");
        if($ugnid){
            $pinglun=xdb::getInstance()->getarray("select * from gongwenpinglun where ugnid=$ugnid");
            $result=xdb::getInstance()->getrow("select * from news where id=$nid");
            $this->show("gongwenreadshow",compact('result','ugnid','pinglun'));
        }else{
            $this->show("out");
        }
    }
    function pinglunadd($xxfget){
        $content=$_POST['content'];
        $ugnid=$_POST['ugnid'];
        xdb::getInstance()->updb("user_gongwen_news", array('readed'=>'y'), array('id'=>$ugnid));
        echo xdb::getInstance()->indb("gongwenpinglun", array('ugnid'=>$ugnid,'content'=>$content,'uid'=>XXF_UID), array('id'=>0));
    }
}